//////////////////////////////////////////////////////////////////////////////
//
//  Created by Philip Mulcahy on 23/01/2013.
//  Copyright (c) 2012 Philip Mulcahy. All rights reserved.
//
//  This file is part of the note-recog library.
//
//  note-recog is free software: you can redistribute it and/or modify
//  it under the terms of version 3 of the GNU Lesser General Public License 
//  as published by the Free Software Foundation.
//
//  note-recog is distributed is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with note-recog.  If not, see <http://www.gnu.org/licenses/>.
//
//////////////////////////////////////////////////////////////////////////////

#ifndef note_recog_SequenceIO_h
#define note_recog_SequenceIO_h

#include <vector>
#include <fstream>

namespace SequenceIO
{


template<typename ITERATOR>
void write(ITERATOR start, ITERATOR end, const char* file_path)
{
    std::ofstream ofs(file_path);
    ITERATOR it(start);
    while(it != end)
    {
        ofs << *it << std::endl;
        ++it;
    }
    ofs.close();
}


template <typename T>
std::vector<T> readToVector(const char* file_path)
{
    std::vector<T> data;
    std::ifstream ifs(file_path);
    while (ifs.good()) {
        const size_t buffsize = 1024;
        char buff[buffsize];
        char * const pbuff = &(buff[0]);
        ifs.getline(pbuff,buffsize);
        const short val = atoi(pbuff);
        data.push_back(val);
    }
    return data;
}

}


#endif
